package cn.wit.summit.chwan.adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.Layout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;

import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.wit.summit.chwan.R;
import cn.wit.summit.chwan.models.dto.CommentBaseBean;
import cn.wit.summit.chwan.models.response.CommentAllListResponse;
import cn.wit.summit.chwan.utils.AccountUtil;
import cn.wit.summit.chwan.utils.DateUtils;
import cn.wit.summit.chwan.utils.DensityUtil;
import cn.wit.summit.chwan.utils.IntentUtil;
import cn.wit.summit.chwan.utils.StringUtils;
import cn.wit.summit.chwan.utils.UtilsMy;
import cn.wit.summit.chwan.widgets.HistogramView;
import cn.wit.summit.chwan.widgets.MStarBar;

/**
 * Created by tangbl on 2017/9/11.
 */

public class CommentAllListFragmentAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context mContext;
    private List<ViewBean> itemBeans;
    private int uid;
    private int myCommentPosition = -1;
    CommentBaseBean mySelf;

    private Map<Integer,ImageView> tempUpIv = new HashMap<>();
    private Map<Integer,ImageView> tempDownIv = new HashMap<>();
    private Map<Integer,TextView> tempUpTv = new HashMap<>();
    private Map<Integer,TextView> tempDownTv = new HashMap<>();

    public CommentAllListFragmentAdapter(Context mContext, int uid, List<ViewBean> itemBeans, Listener mListenr) {
        this.mContext = mContext;
        this.uid = uid;
        this.itemBeans = itemBeans;
        this.mListenr = mListenr;
    }

    public void setUid(int uid) {
        this.uid = uid;
        notifyDataSetChanged();
    }

    public List<ViewBean> getItemBeans() {
        return itemBeans;
    }

    public void setMySelf(CommentBaseBean mySelf) {
        this.mySelf = mySelf;
    }

    public int getMyCommentPosition() {
        if (myCommentPosition == -1) {
            for (int i = 0; i < itemBeans.size(); i++) {
                if (itemBeans.get(i).getViewType() == ViewType.COMMENT &&
                        ((ViewBean.Comment) itemBeans.get(i).getObj()).data.getUid().equals(String.valueOf(uid))) {
                    myCommentPosition = i;
                    break;
                }
            }
        }
        return myCommentPosition;
    }

    public Object getItem(int position) {
        if (itemBeans != null) {
            return itemBeans.get(position).getObj();
        }
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getItemCount() {
        if (itemBeans != null) {
            return itemBeans.size();
        }
        return 0;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        RecyclerView.ViewHolder viewHolder;
        View view;
        if (viewType == ViewType.COMMENT.ordinal()) {
            view = LayoutInflater.from(mContext).inflate(R.layout.item_game_detail_new_comment_view, parent,false);
            viewHolder = new CommentViewHolder(view);
        } else if (viewType == ViewType.EMPTY.ordinal()) {
            view = LayoutInflater.from(mContext).inflate(R.layout.comment_list_empty_view, parent,false);
            viewHolder = new EmptyTitle(view);
        } else if (viewType == ViewType.HEAD.ordinal()) {
            view = LayoutInflater.from(mContext).inflate(R.layout.comment_list_head_view, parent,false);
            viewHolder = new ViewHolderHead(view);
        } else {
            view = LayoutInflater.from(mContext).inflate(R.layout.gamedetail_item_title,  parent,false);
            viewHolder = new ViewHolderTitle(view);
        }
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        int viewType = getItemViewType(position);

        if (viewType == ViewType.COMMENT.ordinal()) {
            ViewBean.Comment viewBean = (ViewBean.Comment) getItem(position);
            final CommentBaseBean commitDataBean = viewBean.data;
            if (viewBean == null) return;
            CommentViewHolder commentViewHolder = (CommentViewHolder) holder;

            if (commitDataBean.getUid().equals(String.valueOf(uid))) {
                commentViewHolder.isMe.setVisibility(View.VISIBLE);
                myCommentPosition = position;
            } else {
                commentViewHolder.isMe.setVisibility(View.GONE);
            }

            if (StringUtils.isEmpty(commitDataBean.getUser_name())) {
                commentViewHolder.userName.setVisibility(View.GONE);
            } else {
                commentViewHolder.userName.setVisibility(View.VISIBLE);
                commentViewHolder.userName.setText(commitDataBean.getUser_name());
            }
            if (android.os.Build.VERSION.SDK_INT == 19) {
                commentViewHolder.content.setText(commitDataBean.getContent().replaceAll("\n", ""));
            } else {
                commentViewHolder.content.setText(commitDataBean.getContent());
            }
            if (commitDataBean.getIs_old() == 1 || commitDataBean.getMobile_phone_model() == null
                    || commitDataBean.getMobile_phone_model().isEmpty())
                commentViewHolder.phoneModle.setVisibility(View.INVISIBLE);
            else {
                commentViewHolder.phoneModle.setVisibility(View.VISIBLE);
                commentViewHolder.phoneModle.setText(commitDataBean.getMobile_phone_model());
            }
            commentViewHolder.pariseNumber.setText(commitDataBean.getPraise_count() + "");
            commentViewHolder.downNumber.setText(commitDataBean.getDespise_count() + "");
            commentViewHolder.messageNumber.setText(commitDataBean.getReply_count() + "");
            long timel = Long.parseLong(commitDataBean.getAdd_times() + "000");
            commentViewHolder.time.setText(DateUtils.FormatForDownloadTime(timel));

            if (commitDataBean.getApproval_rate() != null
                    && Double.valueOf(commitDataBean.getApproval_rate()) > 70)
                commentViewHolder.isGood.setVisibility(View.VISIBLE);
            else
                commentViewHolder.isGood.setVisibility(View.GONE);

            if (commitDataBean.getIs_praise() == 1) {
                commentViewHolder.parise.setImageResource(R.drawable.uped_ic);
            } else {
                commentViewHolder.parise.setImageResource(R.drawable.up_ic);
            }

            if (commitDataBean.getIs_despise() == 1) {
                commentViewHolder.down.setImageResource(R.drawable.downed_ic);
            } else {
                commentViewHolder.down.setImageResource(R.drawable.down_ic);
            }

            UtilsMy.setIconImage(mContext, commitDataBean.getHead_portrait(), commentViewHolder.userIcon);

            setOnPraiseListener(commentViewHolder, commentViewHolder.parise, commentViewHolder.pariseNumber, commitDataBean, position);
            setOnUnPraiseListener(commentViewHolder, commentViewHolder.down, commentViewHolder.downNumber, commitDataBean, position);
            setOnItemListener(commentViewHolder.message, commitDataBean, position);
            setOnItemListener(commentViewHolder.commentAllRootLl, commitDataBean, position);

            //动态判断设置行数
            if (commitDataBean.isShowMore()) {
                commentViewHolder.more.setText("收起");
                commentViewHolder.content.setMaxLines(Integer.MAX_VALUE);
                commentViewHolder.moreUpIv.setVisibility(View.GONE);
            } else {
                commentViewHolder.more.setText("查看全部");
                commentViewHolder.content.setMaxLines(5);
                commentViewHolder.moreUpIv.setVisibility(View.VISIBLE);
            }

            //动态改变显示与否"查看全部"按钮
            final CommentViewHolder finalCommentViewHolder1 = commentViewHolder;
            commentViewHolder.content.post(new Runnable() {
                @Override
                public void run() {
                    Layout l = finalCommentViewHolder1.content.getLayout();
                    if (l != null) {
                        int lines = l.getLineCount();
                        if (lines > 0) {
                            if (lines>5) {
                                finalCommentViewHolder1.more.setVisibility(View.VISIBLE);
                            } else {
                                int num = l.getEllipsisCount(lines - 1);
                                if (num > 0) {
                                    finalCommentViewHolder1.more.setVisibility(View.VISIBLE);
                                } else {
                                    if (commitDataBean.isShowMore()) {
                                        finalCommentViewHolder1.more.setVisibility(View.VISIBLE);
                                    } else {
                                        finalCommentViewHolder1.more.setVisibility(View.GONE);
                                        finalCommentViewHolder1.moreUpIv.setVisibility(View.GONE);
                                    }
                                }
                            }
                        }
                    } else {
                        finalCommentViewHolder1.more.setVisibility(View.GONE);
                        finalCommentViewHolder1.moreUpIv.setVisibility(View.GONE);
                    }
                }
            });

            //监听点击"查看全部"按钮点击事件
            final CommentViewHolder finalCommentViewHolder = commentViewHolder;
            commentViewHolder.more.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String s = finalCommentViewHolder.more.getText().toString();
                    if (s.equals("查看全部")) {
                        if (android.os.Build.VERSION.SDK_INT == 19) {
                            finalCommentViewHolder.content.setText(commitDataBean.getContent());
                        }
                        finalCommentViewHolder.content.setMaxLines(Integer.MAX_VALUE);
                        finalCommentViewHolder.more.setText("收起");
                        finalCommentViewHolder.moreUpIv.setVisibility(View.GONE);
                        commitDataBean.setShowMore(true);
                    } else {
                        if (android.os.Build.VERSION.SDK_INT == 19) {
                            finalCommentViewHolder.content.setText(commitDataBean.getContent().replaceAll("\n", ""));
                        }
                        finalCommentViewHolder.content.setMaxLines(5);
                        finalCommentViewHolder.more.setText("查看全部");
                        finalCommentViewHolder.moreUpIv.setVisibility(View.VISIBLE);
                        commitDataBean.setShowMore(false);
                    }
                }
            });
        } else if (viewType == ViewType.HEAD.ordinal()) {
            ViewHolderHead viewHolderHead = (ViewHolderHead) holder;
            CommentAllListResponse.ScoringDetailsBean scoringDetailsBean = (CommentAllListResponse.ScoringDetailsBean) getItem(position);
            setLinechartData(scoringDetailsBean, viewHolderHead);
        } else if (viewType == ViewType.TITLE.ordinal()) {
            ViewHolderTitle viewHolderTitle= (ViewHolderTitle) holder;
            ViewBean.Comment viewBean = (ViewBean.Comment) getItem(position);
            final CommentBaseBean commitDataBean = viewBean.data;
            if (commitDataBean.getIs_hot() == 1) {
                viewHolderTitle.titleText.setText("热门点评");
            } else {
                viewHolderTitle.titleText.setText("最新点评");
            }
        } else if (viewType == ViewType.EMPTY.ordinal()) {
            EmptyTitle emptyTitle= (EmptyTitle) holder;
        }
    }

    /**
     * 防止快速点击,启动多个同样的界面
     *
     * @return
     */
    long lastClickTime;
    public boolean isFastDoubleClick() {
        long now = System.currentTimeMillis();
        long timeD = now - lastClickTime;
        lastClickTime = now;
        return timeD <= 500;
    }

    private void setLinechartData(CommentAllListResponse.ScoringDetailsBean scoringDetailsBean, ViewHolderHead viewHolderHead) {

        HistogramView[] hvList = {viewHolderHead.oneHv, viewHolderHead.twoHv, viewHolderHead.threeHv, viewHolderHead.fourHv, viewHolderHead.fiveHv};
        String[] hvListColor = {"#F47500", "#FFA423", "#FFB53D", "#FBCD36", "#E4DECA"};
        DecimalFormat decimalFormat = new DecimalFormat("#.0");
        double temp = Double.valueOf(scoringDetailsBean.getTotal_score());
        viewHolderHead.commentHeadPointTx.setText(decimalFormat.format(temp));
        viewHolderHead.commentHeadMstarBar.setStarMark(scoringDetailsBean.getTotal_stars());
        double[] stars = {Double.valueOf(scoringDetailsBean.getStars_score5())
                , Double.valueOf(scoringDetailsBean.getStars_score4())
                , Double.valueOf(scoringDetailsBean.getStars_score3())
                , Double.valueOf(scoringDetailsBean.getStars_score2())
                , Double.valueOf(scoringDetailsBean.getStars_score1())};

        double num = 0;
        double maxLen = 0;
        int maxPoint = 0;
        for (int i = 0; i < stars.length; i++) {
            num += stars[i];
            if (stars[i] > maxLen) {
                maxPoint = i;
                maxLen = stars[i];
            }
        }
//        viewHolderHead.commentHeadNumTx.setText(scoringDetailsBean.getP_count() + "人");
//
//        if (scoringDetailsBean.getP_count() <= 0) {
//            viewHolderHead.commentHeadMstarBar.setStarMark(0);
//            viewHolderHead. comment_head_nopoint_tx.setVisibility(View.VISIBLE);
//            viewHolderHead.commentHeadPointTx.setVisibility(View.GONE);
//            viewHolderHead.commentHeadNumTx.setVisibility(View.GONE);
//        } else {
//            viewHolderHead.point_ll.setVisibility(View.VISIBLE);
//        }

        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, DensityUtil.dp2px(mContext, 10));
        for (int i = 0; i < hvList.length; i++) {
            hvList[i].setAnim(false);
            if (stars[i] == 0)
                hvList[i].setProgress(0);
            else if (i == maxPoint)
                hvList[i].setProgress(1);
            else if (maxLen == stars[i])
                hvList[i].setProgress(1);
            else
                hvList[i].setProgress(stars[i] / maxLen);

            hvList[i].setRateBackgroundColor(hvListColor[i]);
            hvList[i].setLayoutParams(params);
            hvList[i].setOrientation(LinearLayout.HORIZONTAL);
        }


    }

    @Override
    public int getItemViewType(int position) {
        if (this.itemBeans != null) {
            ViewBean bean = this.itemBeans.get(position);
            return bean.getViewType().ordinal();
        }
        return -1;
    }

    private void setOnItemListener(View view, final CommentBaseBean commitDataBean, final int position) {
        view.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (commitDataBean == null)
                    return;
                if (mListenr != null) {
                    mListenr.onRootView(commitDataBean, position);
                }
            }
        });
    }

    private void setOnPraiseListener(final CommentViewHolder commentViewHolder, final ImageView view, final TextView tv, final CommentBaseBean commitDataBean, final int position) {
        tempUpIv.put(position, view);
        tempUpTv.put(position, tv);
        View.OnClickListener temp = new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (isFastDoubleClick()) return;
                if (AccountUtil.getInstance().getUidNotToLogin(mContext) == 0) return;
                if (commitDataBean == null)
                    return;
                if (commitDataBean.getIs_praise() == 1) {
                    subPraise(position);
                    view.setImageResource(R.drawable.up_ic);
                    if (mListenr != null) {
                        mListenr.onPraise(commitDataBean, position, 2);
                    }
                    return;
                } else {
                    commitDataBean.setIs_praise(1);
                }

                if (AccountUtil.getInstance().getAccountData() != null) {
                    view.setImageResource(R.drawable.uped_ic);
                    Animation scaleAnim = AnimationUtils.loadAnimation(mContext, R.anim.scale_reset);
                    view.startAnimation(scaleAnim);
                    scaleAnim.setAnimationListener(new Animation.AnimationListener() {
                        @Override
                        public void onAnimationStart(Animation animation) {

                        }

                        @Override
                        public void onAnimationEnd(Animation animation) {
                            long num = Long.valueOf(tv.getText().toString());
                            tv.setText((num + 1) + "");
                            addPraise(position);

                            if (mListenr != null) {
                                mListenr.onPraise(commitDataBean, position, 1);
                            }
                        }

                        @Override
                        public void onAnimationRepeat(Animation animation) {

                        }
                    });
                } else {
                    IntentUtil.getInstance().goLoginInteractive(mContext);
                }
            }
        };

        view.setOnClickListener(temp);
        tv.setOnClickListener(temp);
    }

    public void addPraise(int position) {
        ViewBean.Comment viewBean = (ViewBean.Comment) getItem(position);

        long num = viewBean.data.getPraise_count();
        viewBean.data.setIs_praise(1);
        viewBean.data.setPraise_count(num + 1);
    }

    public void subPraise(int position) {
        ViewBean.Comment temp = (ViewBean.Comment) getItem(position);
        final CommentBaseBean viewBean = temp.data;

        long num = viewBean.getPraise_count();
        viewBean.setIs_praise(0);
        if (num - 1 < 0) {
            viewBean.setPraise_count(0);
            if (tempUpTv.containsKey(position) && tempUpTv.get(position)!=null) {
                tempUpTv.get(position).setText("0");
            }
        } else {
            viewBean.setPraise_count(num - 1);
            if (tempUpTv.containsKey(position) && tempUpTv.get(position)!=null) {
                tempUpTv.get(position).setText(""+(num - 1));
            }
        }
    }

    public void resetPraise(int position, int state) {
        ViewBean.Comment temp = (ViewBean.Comment) getItem(position);
        final CommentBaseBean viewBean = temp.data;

        long num = viewBean.getPraise_count();
        if (viewBean.getIs_praise() == 1) {
            viewBean.setIs_praise(0);
            if (num - 1 < 0) {
                viewBean.setPraise_count(0);

                if (tempUpIv.containsKey(position) && tempUpIv.get(position)!=null) {
                    tempUpIv.get(position).setImageResource(R.drawable.up_ic);
                    tempUpTv.get(position).setText("0");
                }
            } else {
                viewBean.setPraise_count(num - 1);

                if (tempUpIv.containsKey(position) && tempUpIv.get(position)!=null) {
                    tempUpIv.get(position).setImageResource(R.drawable.up_ic);
                    tempUpTv.get(position).setText(""+(num - 1));
                }
            }
        } else {
            if (state != 1) {
                viewBean.setIs_praise(1);
                viewBean.setPraise_count(num + 1);

                if (tempUpIv.containsKey(position) && tempUpIv.get(position)!=null) {
                    tempUpIv.get(position).setImageResource(R.drawable.uped_ic);
                    tempUpTv.get(position).setText(""+(num + 1));
                }
            }
        }
    }

    public void resetDespise(int position, int state) {
        ViewBean.Comment temp = (ViewBean.Comment) getItem(position);
        final CommentBaseBean viewBean = temp.data;
        long num = Long.valueOf(viewBean.getDespise_count());
        if (viewBean.getIs_despise() == 1) {
            viewBean.setIs_despise(0);
            if (num - 1 < 0) {
                viewBean.setDespise_count("0");

                if (tempDownIv.containsKey(position) && tempDownIv.get(position)!=null) {
                    tempDownIv.get(position).setImageResource(R.drawable.down_ic);
                    tempDownTv.get(position).setText("0");
                }
            } else {
                viewBean.setDespise_count(num - 1 + "");

                if (tempDownIv.containsKey(position) && tempDownIv.get(position)!=null) {
                    tempDownIv.get(position).setImageResource(R.drawable.down_ic);
                    tempDownTv.get(position).setText(""+(num - 1));
                }
            }
        } else {
            if (state != 1) {
                viewBean.setIs_despise(1);
                viewBean.setDespise_count(num + 1 + "");

                if (tempDownIv.containsKey(position) && tempDownIv.get(position)!=null) {
                    tempDownIv.get(position).setImageResource(R.drawable.downed_ic);
                    tempDownTv.get(position).setText(""+(num - 1));
                }
            }
        }
    }

    public void addDespise(int position) {
        ViewBean.Comment viewBean = (ViewBean.Comment) getItem(position);

        long num = Long.valueOf(viewBean.data.getDespise_count());
        viewBean.data.setIs_despise(1);
        viewBean.data.setDespise_count(num + 1 + "");
    }

    public void subDespise(int position) {
        ViewBean.Comment temp = (ViewBean.Comment) getItem(position);
        final CommentBaseBean viewBean = temp.data;

        long num = Long.valueOf(viewBean.getDespise_count());
        viewBean.setIs_despise(0);
        if (num - 1 < 0) {
            viewBean.setDespise_count("0");
            if (tempDownTv.containsKey(position) && tempDownTv.get(position)!=null) {
                tempDownTv.get(position).setText("0");
            }
        }
        else {
            viewBean.setDespise_count((num - 1) + "");
            if (tempDownTv.containsKey(position) && tempDownTv.get(position)!=null) {
                tempDownTv.get(position).setText((num - 1) + "");
            }
        }
    }

    private void setOnUnPraiseListener(final CommentViewHolder commentViewHolder, final ImageView view, final TextView tv, final CommentBaseBean commitDataBean, final int position) {
        tempDownIv.put(position, view);
        tempDownTv.put(position, tv);
        View.OnClickListener temp = new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (isFastDoubleClick()) return;
                if (AccountUtil.getInstance().getUidNotToLogin(mContext) == 0) return;
                if (commitDataBean == null)
                    return;
                if (commitDataBean.getIs_despise() == 1) {
                    subDespise(position);
                    view.setImageResource(R.drawable.down_ic);
                    if (mListenr != null) {
                        mListenr.onUnPraise(commitDataBean, position, 2);
                    }
                    return;
                } else {
                    commitDataBean.setIs_despise(1);
                }

                if (AccountUtil.getInstance().getAccountData() != null) {
                    view.setImageResource(R.drawable.downed_ic);
                    Animation scaleAnim = AnimationUtils.loadAnimation(mContext, R.anim.scale_reset);
                    view.startAnimation(scaleAnim);
                    scaleAnim.setAnimationListener(new Animation.AnimationListener() {
                        @Override
                        public void onAnimationStart(Animation animation) {

                        }

                        @Override
                        public void onAnimationEnd(Animation animation) {
                            long num = Long.valueOf(tv.getText().toString());
                            tv.setText((num + 1) + "");
                            addDespise(position);

                            if (mListenr != null) {
                                mListenr.onUnPraise(commitDataBean, position, 1);
                            }
                        }

                        @Override
                        public void onAnimationRepeat(Animation animation) {

                        }
                    });
                } else {
                    IntentUtil.getInstance().goLoginInteractive(mContext);
                }
            }
        };
        view.setOnClickListener(temp);
        tv.setOnClickListener(temp);
    }

    //region 事件回调
    Listener mListenr = null;

    public Listener getmListenr() {
        return mListenr;
    }

    public void setListenr(Listener mListenr) {
        this.mListenr = mListenr;
    }

    public interface Listener {

        void onPraise(CommentBaseBean bean, int position, int type);//点赞

        void onUnPraise(CommentBaseBean bean, int position, int type);//点踩

        void onRootView(CommentBaseBean bean, int position);//item

        void onClickHead();//item
    }

    class ViewHolder {

    }

    class EmptyTitle extends RecyclerView.ViewHolder {

        public EmptyTitle(View view) {
            super(view);
        }
    }

    class ViewHolderTitle extends RecyclerView.ViewHolder {
        public TextView titleText;
        public View layoutTop;

        public ViewHolderTitle(View view) {
            super(view);
            titleText = view.findViewById(R.id.titleText);
            layoutTop = view.findViewById(R.id.layoutTop);
        }
    }

    class ViewHolderHead extends RecyclerView.ViewHolder {

        private LinearLayout start_ll;
        private LinearLayout point_ll;
        private LinearLayout goCommit;
        private MStarBar commentHeadMstarBar;
        private TextView editText5;
        private TextView comment_head_nopoint_tx;
        private TextView commentHeadPointTx;
        private TextView commentHeadNumTx;
        private HistogramView oneHv, twoHv, threeHv, fourHv, fiveHv;
        public ViewHolderHead(View headView) {
            super(headView);
            oneHv = (HistogramView) headView.findViewById(R.id.oneHv);//#F47500
            twoHv = (HistogramView) headView.findViewById(R.id.twoHv);//#F47500
            threeHv = (HistogramView) headView.findViewById(R.id.threeHv);//#F47500
            fourHv = (HistogramView) headView.findViewById(R.id.fourHv);//#F47500
            fiveHv = (HistogramView) headView.findViewById(R.id.fiveHv);//#F47500
            commentHeadMstarBar = (MStarBar) headView.findViewById(R.id.comment_head_mstarBar);
            commentHeadPointTx = (TextView) headView.findViewById(R.id.comment_head_point_tx);
            comment_head_nopoint_tx = (TextView) headView.findViewById(R.id.comment_head_nopoint_tx);
            commentHeadNumTx = (TextView) headView.findViewById(R.id.comment_head_num_tx);
            editText5 = (TextView) headView.findViewById(R.id.editText5);
            editText5.setText("玩过");
            start_ll = (LinearLayout) headView.findViewById(R.id.start_ll);
            point_ll = (LinearLayout) headView.findViewById(R.id.point_ll);
            headView.findViewById(R.id.goCommit).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mListenr.onClickHead();
                }
            });

            commentHeadMstarBar.setIntegerMark(false);
            commentHeadMstarBar.setEnabled(false);
        }
    }

    class CommentViewHolder extends RecyclerView.ViewHolder {
        private LinearLayout commentAllRootLl;
        private SimpleDraweeView userIcon;
        private TextView userName;
        private TextView isMe;
        private TextView time;
        private ImageView isGood;
        private TextView content;
        private TextView more;
        public View line;
        private TextView phoneModle;
        private ImageView parise;
        private TextView pariseNumber;
        private ImageView down;
        private TextView downNumber;
        private ImageView message;
        private ImageView moreUpIv;
        private TextView messageNumber;

        public CommentViewHolder(View view) {
            super(view);
            commentAllRootLl = (LinearLayout) view.findViewById(R.id.commentAllRootLl);
            userIcon = (SimpleDraweeView) view.findViewById(R.id.usericon);
            userName = (TextView) view.findViewById(R.id.userName);
            isMe = (TextView) view.findViewById(R.id.isMe);
            isGood = (ImageView) view.findViewById(R.id.isGood);
            moreUpIv = (ImageView) view.findViewById(R.id.moreUpIv);
            time = (TextView) view.findViewById(R.id.time);
            content = (TextView) view.findViewById(R.id.content);
            more = (TextView) view.findViewById(R.id.more);
            line = view.findViewById(R.id.line);
            phoneModle = (TextView) view.findViewById(R.id.phoneModle);
            parise = (ImageView) view.findViewById(R.id.parise);
            pariseNumber = (TextView) view.findViewById(R.id.pariseNumber);
            down = (ImageView) view.findViewById(R.id.down);
            downNumber = (TextView) view.findViewById(R.id.downNumber);
            message = (ImageView) view.findViewById(R.id.message);
            messageNumber = (TextView) view.findViewById(R.id.messageNumber);
        }
    }

    public enum ViewType {
        EMPTY,
        TITLE,
        COMMENT,
        REPLY,
        HEAD
    }

    public static class ViewBean {
        ViewType viewType;
        Object obj;

        public ViewBean() {
        }

        public ViewBean(ViewType viewType, Object obj) {
            this.viewType = viewType;
            this.obj = obj;
        }

        public ViewType getViewType() {
            return viewType;
        }

        public void setViewType(ViewType viewType) {
            this.viewType = viewType;
        }

        public Object getObj() {
            return obj;
        }

        public void setObj(Object obj) {
            this.obj = obj;
        }

        public static class Comment {
            public CommentBaseBean data;

            public Comment(CommentBaseBean data) {
                this.data = data;
            }
        }

        public static class Reply {
            public String commentId;
            public CommentBaseBean commentBean;
            public int myAuth;
            public boolean showDivider;
            public int replyItemIndex;
            public boolean lastIndex;
            public boolean hideBottom;

            public Reply(String commentId, CommentBaseBean commentBean, int myAuth, boolean showDivider) {
                this.commentId = commentId;
                this.commentBean = commentBean;
                this.myAuth = myAuth;
                this.showDivider = showDivider;
            }
        }
    }
}
